﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_newsEditdo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            newsEditdo();
        }
    }
    public void newsEditdo() {
        try
        {
            string id = "";
            if (Request["id"] != null && Request["id"].ToString().Trim().Length > 0) id = Request["id"].ToString();

            string channelid = Request["channelid"].ToString();
            if (channelid.Trim().Length == 0) channelid = "0";
            string newName = Request["newName"].ToString();
            string sour = Request["source"].ToString();
            string content = Request["contentFck"].ToString().Replace("<script", "<sscript").Replace("/script>", "/scripts>").Replace("/script >", "/scripts>").Replace("'", "");
            string datestr = Request["date"].ToString();
            if (datestr.Trim().Length == 0) datestr = DateTime.Now.ToString();
            string admin = Session["adminId"].ToString();
            if (admin.Trim().Length == 0) admin = "0";
            string img = Request["img"].ToString();
            string files = Request["files"].ToString();
            string tourl = Request["tourl"].ToString();

            //更新
            if (id.ToString().Trim().Length > 0)
            {
                DB.doNonQuery("update news set channelid="+channelid+",title='"+newName+"',content='"+content+"',addDate='"+datestr+"',admin="+admin+","
                    +"img='"+img+"',filePath='"+files+"',source='"+sour+"',tourl='"+tourl+"' where newid="+id);
                //生成静态页面
                MakeHtml.info(Server.MapPath("/info.htm"), id, Server.MapPath("/info/"));
                Response.Redirect("newsEdit.aspx?id="+id+"&msg=1");
            }
            //添加
            else
            {
                DB.doNonQuery("insert into news(channelid,title,content,addDate,admin,img,clickNum,filePath,isAss,source,tourl) values("
                    + channelid + ",'" + newName + "','" + content + "','" + datestr + "'," + admin + ",'" + img + "',0,'" + files + "',0,'" + sour + "','" + tourl + "')");
                //生成静态页面
                Object obj = DB.getObject("select max(newid) from news");
                if (obj != null)
                {
                    MakeHtml.info(Server.MapPath("/info.htm"), obj.ToString(), Server.MapPath("/info/"));
                }
                Response.Redirect("newsEdit.aspx?msg=1");
            }
        }
        catch (Exception error) {
            Response.Write(error.ToString());
        }
    }
}
